#ifndef MATH_H
#define MATH_H

namespace LibWiimote{

struct LIBWIIMOTE_API vect;
struct quaternion;
struct matrix;

struct vect{
	vect();
	vect(float _x, float _y, float _z);
	vect(const vect & v);

	void ComputeSpherical();
	void ComputeCartesian();

	friend std::ostream & operator << (std::ostream & stream, vect & vect);
	vect operator+(const vect &rhs);
	vect operator-(const vect &rhs);

	float length();

	float rho, phi, theta;
	float x,y,z;
	bool spherical_output;

};
vect operator*(float f, vect & v);

struct quaternion{
	friend struct matrix;
public : 
	void init(vect dir, float angle);
	void init(float yaw, float pitch, float roll);
	void normalize();
	float norm();

private : 
	float x,y,z,w;
};

struct matrix{
public:
	matrix();
	matrix(matrix & m);
	matrix(quaternion q);
	matrix(float * v);
	void init(quaternion q);
	void init(float * v);
	vect mult(vect v);
	matrix mult(matrix & m);
	void setOrigin(vect & v);
	float * get();
private:
	union {
		struct {
			float _m11, _m12, _m13, _h14;
			float _m21, _m22, _m23, _h24;
			float _m31, _m32, _m33, _h34;
			float _tx,  _ty,  _tz,  _tw;
		};
		float mat[16];
	};
};
matrix operator*( matrix &a, matrix &b );

}

#endif